/*
 * Created on 2006-2-7
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.hitrust.gs.action;

import org.apache.struts.upload.FormFile;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.form.*;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.vo.GSManufactureVO;
import com.hitrust.gs.business.GSManufactureProcessor;
import com.hitrust.gs.bean.GSOperatorBean;

/**
 * @author simonyi
 * 
 * 向系统中录入订单
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class GSManufactureInputAction extends GSBaseAction {

    public String execute(GSBaseForm aForm) throws Exception {

        GSManufactureInputForm form = (GSManufactureInputForm) aForm;
        GSOperatorBean bean = (GSOperatorBean) form.getSession().getAttribute(
                GSBaseConstants.LOGIN);

        
        try {
            String manufactureCode = form.getManufacturecode();
            String manufactureName = form.getManufacturename();
            String category = "";
            String category1 = form.getCategory1();
            String category2 = form.getCategory2();
            String category3 = form.getCategory3();
//            if (category3 == null || "".equals(category3)) {
//                category = category2;
//            } else if (category2 == null || "".equals(category2)) {
//                category = category1;
//            } else {
//                category = category3 == null || category3.length() == 0 ? ""
//                        : category3;
//            }
            //添加产品种类
            if(category2.equals("0")){
                category = category1;
              }
              else if(category3.equals("0")){
                  category = category2;
                 }
               else{
                  category = category3;
               }
            String manufacturebrand = form.getManufacturebrand();
            String manufacturetype = form.getManufacturetype();
            String manufacturespec = form.getManfuacturespec();
            String unitprice = form.getUnitprice();
            String quantunit = form.getQuantunit();
            String qualityassureperiod = form.getQualityassureperiod();
            String manufacturername = form.getManufacturername();
            String makearea = form.getMakearea();
            String providerid = form.getProviderid();
            String machinetype = form.getMachinetype();
            String property=form.getProperty();
            String remark=form.getRemark();
            FormFile image = form.getManufactureimage();
            double fileSize = image.getFileSize();
            byte[] buffer = image.getFileData();

            GSManufactureVO vo = new GSManufactureVO();
            vo.gs_manufacture_id = manufactureCode;
            vo.gs_manufacture_name = manufactureName;
            vo.gs_manufacture_category_id = category;
            vo.gs_manufacture_brand = manufacturebrand;
            vo.gs_manufacture_type = manufacturetype;
            vo.gs_manufacture_spec = manufacturespec;
            vo.gs_manufacture_unitprice = unitprice;
            vo.gs_quant_unit = quantunit;
            vo.gs_quality_assure_period = qualityassureperiod;
            vo.gs_manufacturer_name = manufacturername;
            vo.gs_make_area = makearea;
            vo.gs_provider_id = providerid;
            vo.gs_adapt_machine_type = machinetype;
            vo.gs_appender_property=property;
            vo.gs_remark=remark;
            vo.gs_manufacture_image = buffer;
            vo.gs_concentricity_id=manufactureCode;
            vo.operatorId = "";
            //vo.operatorId = bean.getGs_oper_id();
            vo.gs_manufacture_image = buffer;
            
            vo.realpath = form.getSession().getServletContext().getRealPath("/upload");
            //vo.imageName = form.getRequest().getContextPath()+"/upload";
            

            GSManufactureProcessor processor = new GSManufactureProcessor();
            processor.saveManufacture(vo);
            //if(false) throw new GSException ("","");
            return GSBaseConstants.FORWARD_SUCCESS;

        } catch (GSException e) {
            GSLogWriter.error(this, e.getMessage());
            form.getRequest().setAttribute("_error", e.getMessage());
            return GSBaseConstants.FORWARD_ERROR;
        }

    }
}